package com.zlw.rabbitmq.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.sun.corba.se.impl.resolver.FileResolverImpl;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author Zhaoluowei
 * @version 1.0
 * @date 2019/12/22 15:04
 */
public class TopicProducter {

    public static void main(String[] args) throws IOException, TimeoutException {
        //1.
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setVirtualHost("/");
        connectionFactory.setHost("39.100.250.122");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");

        //2
        Connection connection = connectionFactory.newConnection();

        //3.
        Channel channel = connection.createChannel();
        //4. 声明
        String exchangeName = "test_topic_exchange";
        String routingKey = "test.topic.one";
        String routingKey2 = "test.topic.one.zxc";

        //5. 发送

        for (int i = 0; i < 10; i++) {
            String msg = "Hello RabbitMQ Topic TopicProducter -> routingKey Exchange Message ..." + i;
            String msg2 = "Hello RabbitMQ Topic TopicProducter -> routingKey2 Exchange Message ..." + i;
            channel.basicPublish(exchangeName, routingKey, null, msg.getBytes());
            channel.basicPublish(exchangeName, routingKey2, null, msg2.getBytes());
        }


        //6. 关闭
        channel.close();
        connection.close();

    }

}
